//类描述 处理窗体
Ext.define("SHApp.ClientInfo.ContractManage.Form", {
    extend: "BLBTSystem.Form",
    submitUrl: "api/contractmanage?format=json",
    requires: ["SHApp.EmployeeInfo.BasicInfo.CompanyComboBox", "SHApp.ClientInfo.ContractManage.HROComboBox"],
    winWidth: 650,
    winHeight: 300,
    txtCompanyID: "companyID",
    txtHroID: "HroId",
    txtStartDateID: "startID",
    txtEndDateID: "endID",
    txtEffectiveID: "effectiveID",
    txtStartDate: null,
    txtEndDate: null,
    txtEffective: null,
    initComponent: function () {
        var me = this;
        me.txtCompanyID += me.id;
        me.txtHroID += me.id;
        me.txtEffectiveID += me.id;
        me.txtEndDateID += me.id;
        me.txtStartDateID += me.id;
        Ext.apply(this);
        this.createItems();
        this.callParent(arguments);

        me.txtEffective = Ext.getCmp(me.txtEffectiveID);
        me.txtEndDate = Ext.getCmp(me.txtEndDateID);
        me.txtStartDate = Ext.getCmp(me.txtStartDateID);

        me.txtEndDate.on("change", function (objMe, newVal, oldVal, obj) {
            var startDate = me.txtStartDate.getValue();
            var endDate = me.txtEndDate.getValue();

            var s = startDate.getTime();
            var e = endDate.getTime();

            if (s >= e) {
                me.txtEndDate.setValue(startDate);
                me.txtEffective.setValue("0");
            } else {
                var num = Math.round((e - s) / (3600 * 1000 * 24 * 30));
                me.txtEffective.setValue(num);
            }
        })
        me.txtStartDate.on("change", function (objMe, newVal, oldVal, obj) {
            var startDate = me.txtStartDate.getValue();
            var endDate = me.txtEndDate.getValue();

            var s = startDate.getTime();
            var e = endDate.getTime();

            if (s >= e) {
                me.txtEndDate.setValue(startDate);
                me.txtEffective.setValue("0");
            } else {
                var num = Math.round((e - s) / (3600 * 1000 * 24 * 30));
                me.txtEffective.setValue(num);
            }
        })
    },
    createItems: function () {
        var me = this;
        this.items = [{
            width: 300,
            border: false,
            bodyStyle: "background:#DFE9F6",
            layout: { type: "vbox", align: "stretch" },
            items: [
				{
				    xtype: "textfield",
				    fieldLabel: "ID",
				    name: "Id",
				    hidden: true
				}, {
				    xtype: "textfield",
				    fieldLabel: "<span style='color:red'>*</span>合体编号",
				    allowBlank: false,
				    blankText: "请输入合体编号!",
				    name: "Code"
				}, {
				    xtype: "textfield",
				    fieldLabel: "<span style='color:red'>*</span>合体名称",
				    allowBlank: false,
				    blankText: "请输入合体名称!",
				    name: "Name"
				}, {
				    xtype: "companyComboBox",
				    fieldLabel: "<span style='color:red'>*</span>甲方名称",
				    name: "CompanyID",
				    listeners: {
				        select: function (c, r, o) {
				            if (r != null && r.length > 0) {
				                me.down("#" + me.txtCompanyID).setValue(this.getDisplayValue());
				            }
				        }
				    }
				}, {
				    fieldLabel: "<span style='color:red'>*</span>乙方名称",
				    xtype: "hrocombobox",
				    name: "HroID",
				    listeners: {
				        select: function (c, r, o) {
				            if (r != null && r.length > 0) {
				                me.down("#" + me.txtHroID).setValue(this.getDisplayValue());
				            }
				        }
				    }
				}, {
				    xtype: "datefield",
				    fieldLabel: "<span style='color:red'>*</span>签订日期",
				    allowBlank: false,
				    blankText: "请输入签订日期!",
				    value: new Date(),
				    name: "SignDateTime",
				    format: 'Y-m-d'
				}, {
				    xtype: "datefield",
				    fieldLabel: "<span style='color:red'>*</span>合同起始日期",
				    allowBlank: false,
				    blankText: "请输入合同起始日期!",
				    value: new Date(),
				    name: "StartDateTime",
				    format: 'Y-m-d',
				    id: me.txtStartDateID
				}, {
				    xtype: "datefield",
				    fieldLabel: "<span style='color:red'>*</span>合同截止日期",
				    allowBlank: false,
				    blankText: "请输入合同截止日期!",
				    value: new Date(),
				    id: me.txtEndDateID,
				    name: "EndDateTime",
				    format: 'Y-m-d'
				}, {
				    fieldLabel: "合同附件ID",
				    xtype: "textfield",
				    name: "AdjunctID",
				    maxLength: 50,
				    hidden: true
				}]
        }, {
            width: 300,
            border: false,
            bodyStyle: "background:#DFE9F6",
            layout: { type: "vbox", align: "stretch" },
            items: [{
                fieldLabel: "甲方ID",
                xtype: "textfield",
                name: "CompanyName",
                maxLength: 50,
                hidden: true,
                id: me.txtCompanyID
            }, {
                fieldLabel: "乙方ID",
                xtype: "textfield",
                name: "HroName",
                maxLength: 50,
                hidden: true,
                id: me.txtHroID
            }, {
                fieldLabel: "<span style='color:red'>*</span>合同有效期",
                allowBlank: false,
                blankText: "请输入合同有效期!",
                xtype: "textfield",
                name: "EffectiveDate",
                maxLength: 50,
                readOnly: true,
                id: me.txtEffectiveID
            }, {
                fieldLabel: "合同类型",
                xtype: "radiogroup",
                //name: "ConstractType",
                columns: 2,
                items: [
                        { name: "ConstractType", boxLabel: "新签", inputValue: "新签" },
                        { name: "ConstractType", boxLabel: "续签", inputValue: "续签" }
                    ]
            }, {
                fieldLabel: "合同状态",
                xtype: "radiogroup",
                //name: "ConstractState",
                columns: 2,
                items: [
                    { name: "ConstractState", boxLabel: "生效", inputValue: "生效" },
                    { name: "ConstractState", boxLabel: "终止", inputValue: "终止" }
                ]
            }, {
                fieldLabel: "合同规模",
                xtype: "textfield",
                name: "ConstractScale",
                maxLength: 50
            }, {
                fieldLabel: "合同附件",
                xtype: "textfield",
                name: "AdjunctName",
                maxLength: 50
            }, {
                fieldLabel: "备注",
                xtype: "textareafield",
                name: "Remarks",
                maxLength: 200,
                rows: 3,
                cols: 150
            }]
        }];
    }
})